using I2.Loc;
using UnityEngine;

public class TitanfallUI : MonoBehaviour
{
	public static TitanfallUI instance;

	public UISprite spawnTitanButtonBar;

	public GameObject spawnTitanButtonInactive;

	public GameObject spawnTitanButtonEnabled;

	public GameObject spawnTitanButtonDisabled;

	public UITexture activeTitanTexure1;

	public UITexture activeTitanTexure2;

	public UITexture inactiveTitanTexture;

	public GameObject tutorArrow;

	public GameObject tutorText;

	public UILabel timer;

	public UILabel place;

	public UILabel kills;

	private string currentTitanName = string.Empty;

	private void Awake()
	{
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public void CantSpawnTitan()
	{
		if (TitanSpawner.instance.canSpawnTitan)
		{
			GameplayNotificationController.instance.AddNotification(ScriptLocalization.Get("Game_Common/Titan_youCantSummon"), 0, false);
		}
	}

	public void SpawnTitan()
	{
		TitanSpawner.instance.SpawnTitan();
	}

	private void Update()
	{
		if (PlayerBehavior.MyPlayer != null && PlayerBehavior.MyPlayer.inCar && PlayerBehavior.MyPlayer.currentCar is TitanBehavior)
		{
			spawnTitanButtonBar.gameObject.SetActive(false);
			return;
		}
		if (currentTitanName != settings.SelectedTitanName)
		{
			SetTitanTextures(settings.SelectedTitanName);
		}
		spawnTitanButtonBar.gameObject.SetActive(true);
		if (TitanSpawner.instance.canSpawnTitan)
		{
			spawnTitanButtonInactive.SetActive(false);
			if (TitanSpawner.instance.canSpawnTitanHere)
			{
				spawnTitanButtonEnabled.SetActive(true);
				spawnTitanButtonDisabled.SetActive(false);
			}
			else
			{
				spawnTitanButtonEnabled.SetActive(false);
				spawnTitanButtonDisabled.SetActive(true);
			}
		}
		else
		{
			spawnTitanButtonInactive.SetActive(true);
			spawnTitanButtonDisabled.SetActive(false);
			spawnTitanButtonEnabled.SetActive(false);
		}
		spawnTitanButtonBar.fillAmount = TitanSpawner.instance.titanSpawnRecharge / TitanSpawner.instance.maxSpawnRechargeValue;
	}

	public void SetTitanTextures(string titanName)
	{
		if (!string.IsNullOrEmpty(titanName))
		{
			currentTitanName = titanName;
			activeTitanTexure1.mainTexture = Resources.Load<Texture>("AtlasGame/AG_" + titanName);
			activeTitanTexure2.mainTexture = Resources.Load<Texture>("AtlasGame/AG_" + titanName);
			inactiveTitanTexture.mainTexture = Resources.Load<Texture>("AtlasGame/AG_" + titanName + "_Disabled");
		}
	}

	public void SetMyPlace(int place)
	{
		this.place.text = place.ToString();
	}
}
